import React, { forwardRef, useState, Ref, useImperativeHandle } from 'react';

type IndexRef = {
    setList: (newList: any[]) => void;
};

const Index = forwardRef<IndexRef, {}>((props, ref) => {
    const [list, setList] = useState(['元素.1', '元素.2']);

    if (Number(sessionStorage.getItem('parent-koa') ?? 0) > 0) {
        throw new Error('我抛出了一个错误！');
    }

    useImperativeHandle(ref, () => ({
        setList,
    }));

    return (
        <>
            <h1>
                parent:{' '}
                <span style={{ fontSize: 14, color: '#000' }}>{list.map((str) => str.concat('1')).join('、')}</span>
            </h1>
        </>
    );
});

export default Index;
